package offer.singleton;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/18 10:10
 */
public class DoubleCheckSingleton {

    private static volatile DoubleCheckSingleton singleton = null;

    private static int val = 0;

    private DoubleCheckSingleton(){}

    public static DoubleCheckSingleton getInstance(){
        if(singleton == null){
            synchronized (DoubleCheckSingleton.class){
                if (singleton == null)
                    singleton = new DoubleCheckSingleton();
            }
        }
        return singleton;
    }

    public int addVal(){
        return ++val;
    }

}
